//
//  ShareWeiBo.m
//  LaoShan
//
//  Created by sendInfo on 2013-12-27.
//  Copyright (c) 2013年 dongMac. All rights reserved.
//

#import "ShareWeiBo.h"
#import <Social/Social.h>

@implementation ShareWeiBo
+ (void)shareSinaWeiBoWithContent:(NSString *)text image:(UIImage *)img delegate:(UIViewController*)delegate
{
    
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
        DLog(@"available!");
        SLComposeViewController *social = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
        SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
            if (result == SLComposeViewControllerResultCancelled) {
                DLog(@"cancelled");
            }else{
                
                DLog(@"done");
            }
            [social dismissViewControllerAnimated:YES completion:nil];
        };
        
        social.completionHandler = myBlock;
        NSURL *url = [NSURL URLWithString:@"http://www.weibo.com/"];
        [social setInitialText:text];
        [social addImage:img];
        [social addURL:url];
        [delegate presentViewController:social animated:YES completion:nil];
    }else{
        
        DLog(@"unavailable");
        ALERT_WARN(@"分享不可用,如未绑定账号，请在系统设置里绑定相关账号以后再次尝试");
        
    }
    
}
+ (void)shareTencentWeiBoWithContent:(NSString *)text image:(UIImage *)img delegate:(UIViewController*)delegate
{
    
    if (isIOS6) {
        ALERT_WARN(@"当前系统版本不支持腾讯微博分享,请升级后再次尝试");
        return;
    }
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTencentWeibo]) {
        DLog(@"available!");
        SLComposeViewController *social = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTencentWeibo];
        SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
            if (result == SLComposeViewControllerResultCancelled) {
                
                DLog(@"cancelled");
                
            }else{
                
                DLog(@"done");
            }
            [social dismissViewControllerAnimated:YES completion:nil];
        };
        
        social.completionHandler = myBlock;
        NSURL *url = [NSURL URLWithString:@"http://t.qq.com/"];
        [social setInitialText:text];
        [social addImage:img];
        [social addURL:url];
        
        [delegate presentViewController:social animated:YES completion:nil];
    }else{
        
        DLog(@"unavailable");
        ALERT_WARN(@"分享不可用,如未绑定账号，请在系统设置里绑定相关账号以后再次尝试");
    }
}
@end
